<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8" />
    <title>修改用户</title>
    <link rel="stylesheet" type="text/css" href="../../lib/layui/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="../../lib/layui/css/login.css" />
    <script type="text/javascript" src="../../lib/layui/layui.js"></script>
</head>

<body>
<div class="login-wrapper" style="background-color: lightgray">
    <div class="login-body">
        <div class="layui-card">
            <div class="layui-card-header">
                修改用户
            </div>
            <div class="layui-card-body layui-form layui-form-pane"  style="width: 300px">
                <!--用户名-->
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
                    <div class="layui-input-inline">
                        <input name="username" type="text" autocomplete="off" placeholder="用户名" class="layui-input" disabled>
                    </div>
                    <div class="layui-form-mid" style="color: red;">*</div>
                </div>
                <!--姓名-->
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
                    <div class="layui-input-inline">
                        <input name="realname" type="text" required lay-verify="required" autocomplete="off" placeholder="姓名" class="layui-input">
                    </div>
                    <div class="layui-form-mid" style="color: red;">*</div>
                </div>
                <!--选定角色-->
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-note"></i></label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="role[program]" lay-skin="primary" title="项目" checked="">
                        <input type="checkbox" name="role[develop]" lay-skin="primary" title="开发">
                        <input type="checkbox" name="role[test]" lay-skin="primary" title="测试">
                    </div>
                </div>
                <!--提交注册-->
                <div class="layui-form-item">
                    <button lay-filter="register-submit" class="layui-btn layui-btn-fluid layui-btn-radius" lay-submit>立即提交</button>
                </div>
            </div>
        </div>
    </div>
    <div class="login-footer">
        <p>© 2019 </p>
    </div>
</div>

<script>
    layui.config({
        base: 'module/'
    }).use(['form'], function() {
        var $ = layui.jquery;
        var form = layui.form;

        // 表单提交
        form.on('submit(register-submit)', function(obj) {
            var field = obj.field;

            $.ajax({
                url: 'http://localhost:8080/user/register',
                data: field,
                contentType: "application/x-www-form-urlencoded",
                type: 'POST',
                xhrFields: {
                    withCredentials: true
                },
                success: function(data) {
                    if(data.status == "success") {
                        layer.msg('注册成功', {
                            icon: 1,
                            time: 1000
                        }, function() {
                            //登录后不可再返回登录页
                            //location.replace('index.html');
                            location.href = "index.html";
                        });
                    } else {
                        layer.msg(data.data.errMsg, {
                            icon: 5,
                            time:1000
                        });
                    }
                },
                error: function(xhr) {
                    console.log('error');
                    console.log(xhr);
                    layer.msg('请按F12查看控制台信息', {
                        icon: 5,
                        time:1000
                    });
                }
            });
        });
    });
</script>
</body>

</html>